<template>
  <div>
    <city-header></city-header>
    <city-search :cities="alphabetList"></city-search>
    <city-list
      :hotCities="hotCities"
      :alphabetList="alphabetList"
      :letter="letter"
    ></city-list>
    <city-alphabet
      :alphabetList="alphabetList"
      @scrollInto="scrollInto"
    ></city-alphabet>
  </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'

export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data: function () {
    return {
      letter: '',
      alphabetList: {},
      hotCities: []
    }
  },
  methods: {
    getCityInfo () {
      var url = '/api/msdk/proxy/query_common_city'
      this.$api
        .mockdata(url)
        .then(res => {
          if (res.status && res.status === 200) {
            this.alphabetList = res.data.CityAlphabetData.alphabetList
            this.hotCities = res.data.CityListData.hotCities
          }
        })
        .catch(e => {
          console.warn(e)
        })
    },
    scrollInto (val) {
      this.letter = val
    }
  },
  mounted: function () {
    this.getCityInfo()
  }
}
</script>

<style></style>
